package com.xl.basic.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * 全局的线程池配置
 */
@Configuration
public class ThreadPoolConfig {
    @Bean
    public ExecutorService getThreadPool() {
        int cpu = Runtime.getRuntime().availableProcessors();
        return new ThreadPoolExecutor(cpu, cpu * 2 + 1, 12, TimeUnit.HOURS,
                new LinkedBlockingQueue<>(),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy()
        );

    }
}
